﻿//***************************************html创建*****************************************************************
//创建模块html
//isWrap 是否包含容器（div class="class=boxWrap"） 0 包含容器  1 不包含
function createModuleHtml(moduleEntity, isWrap) {

    var titleStyle = "m-bg" + moduleEntity.TitleStyle;
    var html = "";
    html += ['<li data-id=' + moduleEntity.ModuleId + '>'].join()
    if (moduleEntity.ModuleType == 0) {

        if (isWrap != 1) {
            html += ['<div id=' + moduleEntity.ModuleId + ' class="boxWrap">'].join("");
        }

        html += [' <div   class="jumbotron ">',
            '<div>'].join("");

        if (moduleEntity.IsHideTitle == 0) {

            html += TitleModule[entity.TitleStyle][0] + moduleEntity.Title + TitleModule[entity.TitleStyle][1]

        }
        html += ['<div class="jwrap">' + moduleEntity.ModuleContent,

                            '</div>',
                        '</div>',
                       '</div>'].join("");



        html += ['<div name="lay" onclick=(ModuleEdit(this)) class="layoutview"data-type=' + moduleEntity.ModuleType + ' data-id=' + moduleEntity.ModuleId + ' >'].join("");
        html += ['<span class="module_txicon_white text-center">',
           '<i class="clicon-module-imgtxt text-white" style="font-size:44px;"></i>',
           '<div class="text-white" >图文</div>',
           '</span>',
           '<div class="btn_group">'].join("");
        html += ['<div class="group_item fl" onclick="DelClick(this,event)"><s name="del" data-id=' + moduleEntity.ModuleId + ' class="icon delete" title="点击删除" ></s><span>删除</span></div>'].join("");
        html += ['</div>'].join("");
        if (isWrap != 1) {
            html += ['</div>'].join("");
        }
        html += ['</div>'].join("");
    }
    else if (moduleEntity.ModuleType == 1) {
        var str = CreateNavHtml(moduleEntity);
        if (isWrap != 1) {
            html += ['<div id=' + moduleEntity.ModuleId + ' class="boxWrap">'].join("");
        }
        html += [' <div  class="jumbotron ">' + str + '</div>'].join("");
        html += ['<div name="lay" onclick=(ModuleEdit(this)) class="layoutview"data-type=' + moduleEntity.ModuleType + ' data-id=' + moduleEntity.ModuleId + ' >'].join("");
        html += ['<span class="module_wzdhicon_white text-center">',
      '<i class="clicon-module-imgtxt text-white" style="font-size:44px;"></i>',
      '<div class="text-white" >网址导航</div>',
      '</span>',
      '<div class="btn_group">'].join("");
        html += ['<div class="group_item fl" onclick="DelClick(this,event)"><s name="del" data-id=' + moduleEntity.ModuleId + ' class="icon delete" title="点击删除" ></s><span>删除</span></div>'].join("");
        html += ['</div>'].join("");
        if (isWrap != 1) {
            html += ['</div>'].join("");
        }
        html += ['</div>'].join("");
    }

    else if (moduleEntity.ModuleType == 2) {

        moduleEntity.ModuleContent = $.HtmlHelper.GetProductTableHtml();

        if (isWrap != 1) {
            html += ['<div id=' + moduleEntity.ModuleId + ' class="boxWrap">'].join("");
        }


        html += [' <div   class="jumbotron ">',
            '<div>'].join("");

        if (moduleEntity.IsHideTitle == 0) {

            html += TitleModule[entity.TitleStyle][0] + moduleEntity.Title + TitleModule[entity.TitleStyle][1]

        }
        html += ['<div class="jwrap">' + moduleEntity.ModuleContent,

                            '</div>',
                        '</div>',
                       '</div>'].join("");

        html += ['<div name="lay" onclick=(ModuleEdit(this)) class="layoutview"data-type=' + moduleEntity.ModuleType + ' data-id=' + moduleEntity.ModuleId + ' >'].join("");
        html += ['<span class="module_cpxxicon_white text-center">',
           '<i class="clicon-module-imgtxt text-white" style="font-size:44px;"></i>',
           '<div class="text-white" >产品信息</div>',
           '</span>',
           '<div class="btn_group">'].join("");
        html += ['<div class="group_item fl" onclick="DelClick(this,event)"><s name="del" data-id=' + moduleEntity.ModuleId + ' class="icon delete" title="点击删除" ></s><span>删除</span></div>'].join("");
        html += ['</div>'].join("");
        if (isWrap != 1) {
            html += ['</div>'].join("");
        }
        html += ['</div>'].join("");
    }
    else if (moduleEntity.ModuleType == 3) {

        if (isWrap != 1) {
            html += ['<div id=' + moduleEntity.ModuleId + ' class="boxWrap">'].join("");
        }


        html += [' <div   class="jumbotron ">',
            '<div>'].join("");

        if (moduleEntity.IsHideTitle == 0) {

            html += TitleModule[entity.TitleStyle][0] + moduleEntity.Title + TitleModule[entity.TitleStyle][1]

        }
        html += ['<div class="jwrap">' + moduleEntity.ModuleContent,

                            '</div>',
                        '</div>',
                       '</div>'].join("");

        html += ['<div name="lay" onclick=(ModuleEdit(this)) class="layoutview"data-type=' + moduleEntity.ModuleType + ' data-id=' + moduleEntity.ModuleId + ' >'].join("");
        html += ['<span class="module_qyjlicon_white text-center">',
           '<i class="clicon-module-imgtxt text-white" style="font-size:44px;"></i>',
           '<div class="text-white" >窜货信息</div>',
           '</span>',
           '<div class="btn_group">'].join("");
        html += ['<div class="group_item fl" onclick="DelClick(this,event)"><s name="del" data-id=' + moduleEntity.ModuleId + ' class="icon delete" title="点击删除" ></s><span>删除</span></div>'].join("");
        html += ['</div>'].join("");
        if (isWrap != 1) {
            html += ['</div>'].join("");
        }
        html += ['</div>'].join("");
    }
    else if (moduleEntity.ModuleType == 4) {

        if (isWrap != 1) {
            html += ['<div id=' + moduleEntity.ModuleId + ' class="boxWrap">'].join("");
        }


        html += [' <div   class="jumbotron ">',
            '<div>'].join("");

        if (moduleEntity.IsHideTitle == 0) {

            html += TitleModule[entity.TitleStyle][0] + moduleEntity.Title + TitleModule[entity.TitleStyle][1]

        }
        html += ['<div class="jwrap">' + moduleEntity.ModuleContent,

                            '</div>',
                        '</div>',
                       '</div>'].join("");

        html += ['<div name="lay" onclick=(ModuleEdit(this)) class="layoutview"data-type=' + moduleEntity.ModuleType + ' data-id=' + moduleEntity.ModuleId + ' >'].join("");
        html += ['<span class="module_ppwhicon_white text-center">',
           '<i class="clicon-module-imgtxt text-white" style="font-size:44px;"></i>',
           '<div class="text-white" >品牌文化</div>',
           '</span>',
           '<div class="btn_group">'].join("");
        html += ['<div class="group_item fl" onclick="DelClick(this,event)"><s name="del" data-id=' + moduleEntity.ModuleId + ' class="icon delete" title="点击删除" ></s><span>删除</span></div>'].join("");
        html += ['</div>'].join("");
        if (isWrap != 1) {
            html += ['</div>'].join("");
        }
        html += ['</div>'].join("");
    }








    html += ['</li>'].join()
    return html;
}

//创建导航html

function createNavhtml(navEntity) {


    var html = "";

    html = ['<tr  id="' + navEntity.NavId + '"  >',
        '<td class="tdtxt">',
         ' <div   class="m-ico-edit" >',
         '                <img  src=' + navEntity.Ico + ' />',
         '               <p class="f-di" >' + navEntity.NavName + '</p>',
         '</div> ',
        '</td>',
        '<td>',
 '                <div>',
 '                    <a name="navedit" data-navId=' + navEntity.NavId + ' onclick="$.MGJ.DiamondEdition.Dialog_NavEdit(this)" role="button">',
 '                          <img src="Content/webImgs/TraceSource/Ico/btn_edit.png" /> ',
 '                    </a>',
         '                    <a  name="navdel" data-id=' + navEntity.NavId + ' onclick=(navdel(this)) role="button">',
 '                          <img src="Content/webImgs/TraceSource/Ico/btn_delete.png" /> ',
 '                    </a>',
 '                </div>',

 '      </td>',
 '       </tr>'].join("");


    return html;
}


//***************************************html创建*****************************************************************
//***************************************公共函数*****************************************************************


function hideAll() {
    var list = $(".rdisplay");
    for (var i = 0; i < list.length; i++) {
        $(list[i]).hide();
    }
    $(".rightc").hide();
};

//***************************************html创建*****************************************************************

//***************************************模块增删改查*****************************************************************




//网址导航保存
function SaveNavModule() {

    var title = $("#wzdhTitle").val();
    var navStyle = $('input:radio[name="NavStyle"]:checked').val();
    var IsHideTitle = $('input:radio[name="IsHideTitle2"]:checked').val();

    moduleEntity.Title = title;
    moduleEntity.NavStyle = navStyle;
    moduleEntity.IsHideTitle = IsHideTitle;

    $.ajax({
        type: "post",
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        url: "/OriginsMaterial/" + "ModuleSave",
        data: "{\"model\":" + JSON.stringify(moduleEntity) + "}",
        cache: false,
        success: function (msg) {
            hideAll();
            refreshModule(moduleEntity)
        },
        error: function (jqXHR, textStatus, errorThrown) {
            $.L.msgError(jqXHR.responseText)
        }
    });
}


//图文模块保存
function SavetwModule() {

    var title = $("#Title").val()
    var IsHide = $('input:radio[name="IsHide"]:checked').val();
    var IsHideTitle = $('input:radio[name="IsHideTitle"]:checked').val();
    var moduleContent = ue.getContent();

    moduleEntity.Title = title;
    moduleEntity.IsHide = IsHide;
    moduleEntity.IsHideTitle = IsHideTitle;
    moduleEntity.ModuleContent = moduleContent;

    $.ajax({
        type: "post",
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        url: "/OriginsMaterial/" + "ModuleSave",
        data: "{\"model\":" + JSON.stringify(moduleEntity) + "}",
        cache: false,
        success: function (msg) {
            hideAll();
            refreshModule(moduleEntity);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            $.L.msgError(jqXHR.responseText)
        }
    });

}

//产品信息模块保存

function cpxxModuleSave(obj) {

    var combine = $.extend(moduleEntity, obj);
    $.ajax({
        type: "POST",
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        url: "/OriginsMaterial/" + "ModuleSave",
        data: "{\"model\":" + JSON.stringify(combine) + "}",
        success: function (result) {
            hideAll();
            refreshModule(moduleEntity);



        },
        error: function (jqXHR) {
            $.L.msgError(jqXHR.responseText)
        }
    })




}






//*************************保存后续操作*************

function refreshModule(moduleEntity) {

    var html = createModuleHtml(moduleEntity, 1);
    var id = moduleEntity.ModuleId;
    $("#" + id).html(html);
}

//***************************************模块保存end*****************************************************************

function CreateNavHtml(moduleEntity) {

    var moduleId = moduleEntity.ModuleId;
    var html = AddContent(moduleEntity);
    var titleStyle = "m-bg" + entity.TitleStyle;
    if (moduleEntity.IsHideTitle == 0) {
        wrapHtml = ['<div >',
                       //'<p name="moduleTitle" class="jtitle ' + titleStyle + '">' + moduleEntity.Title + '</p>',
                       TitleModule[entity.TitleStyle][0] + moduleEntity.Title + TitleModule[entity.TitleStyle][1],
                         '<div class="jwrap">',
                           '<div class="row-fluid" >' + html + '</div>',
                         '</div>',
                    '</div>'
        ].join("");
    }
    else {
        wrapHtml = ['<div >',
                     '<div class="jwrap">',
                       '<div class="row-fluid" >' + html + '</div>',
                       '</div>',
                     '</div>'
        ].join("");
    }

    return wrapHtml;
}

function AddContent(moduleEntity) {
    var html = "";
    $.ajax({
        type: "POST",
        dataType: 'json',
        url: "/OriginsMaterial/" + "GetNavListByModuleId?id=" + moduleEntity.ModuleId,
        async: false,
        success: function (navList) {

            if (navList.length == 0) {
                return
            }

            for (var i = 0; i < navList.length; i++) {
                var navEntity = navList[i];
                if (navEntity.LinkGoto == "") {
                    navEntity.LinkGoto = "unknow";
                }
                if (navEntity.PageGoto == "") {

                    navEntity.PageGoto = "unknow";
                }
                var NavClass = "div0";
                if (moduleEntity.NavStyle == 0) {//一行一项
                    NavClass = "col-xs-12 text-center";
                }
                if (moduleEntity.NavStyle == 1) {//一行两项
                    NavClass = "col-xs-6 text-center";
                }
                if (moduleEntity.NavStyle == 2) {

                    NavClass = "col-xs-4 text-center";//一行三项
                }
                if (moduleEntity.NavStyle == 3) {//智能排序
                    NavClass = "col-xs-3 text-center";
                }
                html += [
                    '        <div class="' + NavClass + '"  name="navLink"  action=' + navEntity.Action + ' link=' + navEntity.LinkGoto + ' materialGoto=' + navEntity.MaterialGoto + ' pageGoto=' + navEntity.PageGoto + ' id=' + navEntity.NavId + ' >',
               '                <img class="ico" src="' + navEntity.Ico + '"    />',
                           '               <font class="iosTest">' + navEntity.NavName + '</font>',

               '        </div> ',
                ].join("");
            }
            return html;
        },
        error: function (jqXHR, textStatus, errorThrown) {

            $.L.msgError(jqXHR.responseText);
        }

    });
    return html;
}





/////////////////////////////////////////////////////序列化表单//////

(function ($) {
    $.fn.extend({
        serializeObject: function () {
            if (this.length > 1) {
                return false;
            }
            var arr = this.serializeArray();
            var obj = new Object;
            $.each(arr, function (k, v) {
                obj[v.name] = v.value;
            });
            return obj;
        }
    });
})(jQuery);








